package com.example.login.Controller;

import com.example.login.Pojo.User;
import com.example.login.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    UserService us;
    @GetMapping("/buyer")
    public String jump()
    {
        return "登录";
    }
    @RequestMapping("/userLogin")
    public String login(@RequestParam("BuyerAccount") String name,
                        @RequestParam("BuyerPassword") String password,
                        Model model,
                        HttpSession httpSession)
    {
         if(us.isUser(name,password,httpSession))//是否成功登录
         {
             return "redirect:/";
         }
         else{
             model.addAttribute("msg","用户名或密码错误");
             return "登录";
         }
    }
    @RequestMapping("/UserRegister")
    public String UserRegister(@RequestParam("UserName") String name,
                               @RequestParam("UserPassword") String password, Model model){
        us.Register(name,password);
        //System.out.println(name+password);
        return "登录";
    }

}
